#!/usr/bin/env  python
#conding:utf-8
import os
import sys
import psutil
def zabbix_faild():
    print "ZBX_NOTSUPPORTED"
    sys.exit(2)

if len(sys.argv)  != 3:
    zabbix_faild()

indexkeys = ['load','memory','swap','','']
memindexs = ['total','used','free','used_percent','buffers','cached','active','inactive']
swapindexs = ['total','used','free','used_percent','sin','sout']
returnval = None

if sys.argv[1] in indexkeys:
    if sys.argv[1] == 'load':
        if sys.argv[2] == '1':
            returnval = os.getloadavg()[0]
        elif sys.argv[2] == '5':
            returnval = os.getloadavg()[1]
        elif sys.argv[2] == '15':
            returnval = os.getloadavg()[2]
        else:
            zabbix_faild()
    elif sys.argv[1] == 'memory':
        mem = psutil.virtual_memory()
        if sys.argv[2] not in memindexs:
            zabbix_faild()
        elif sys.argv[2] == 'total':
            returnval = mem.total
        elif sys.argv[2] == 'used':
            returnval = mem.used
        elif sys.argv[2] == 'free':
            returnval = mem.free
        elif sys.argv[2] == 'used_percent':
            returnval = mem.percent
        elif sys.argv[2] == 'active':
            returnval = mem.active
        elif sys.argv[2] == 'inactive':
            returnval = mem.inactive
        elif sys.argv[2] == 'buffers':
            returnval = mem.buffers
        elif sys.argv[2] == 'cached':
            returnval = mem.cached
        else:
            zabbix_faild()
    elif sys.argv[1] == 'swap':
        swap = psutil.swap_memory()
        if sys.argv[2] not in swapindexs:
            zabbix_faild()
        elif sys.argv[2] == 'total':
            returnval = swap.total
        elif sys.argv[2] == 'used':
            returnval = swap.used
        elif sys.argv[2] == 'free':
            returnval = swap.free
        elif sys.argv[2] == 'used_percent':
            returnval = swap.percent
        elif sys.argv[2] == 'sin':
            returnval = swap.sin
        elif sys.argv[2] == 'sout':
            returnval = swap.sout
        else:
            zabbix_faild()
else:
    zabbix_faild()

print returnval